package com.qn.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 待发送集合对象
 *
 * @author olo
 */
@Data
public class DueOutMail {
    /**
     * 要发送的邮件集合
     */
    private List<String> list;

    public void setList(List<String> list) {
        this.list = removeNullList(list);
    }

    /**
     * 标题
     */
    private String title;
    /**
     * 要发送的内容
     */
    private String message;
    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia")
    private Date beginDate;
    /**
     * 发送结果
     */
    private MailSendStatus mailSendStatus;

    /**
     * 遍历集合，将不合格的邮箱过滤掉
     */
    List<String> removeNullList(List<String> list) {
        //去空
        list.removeAll(Collections.singleton(null));
        //jdk8新特性去重  不会改变原数组,所以需要赋值
        list = list.stream().distinct().collect(Collectors.toList());
        return list;
    }

    public DueOutMail(List<String> list, String title, String message) {
        this.list = list;
        this.title = title;
        this.message = message;
        this.beginDate = new Date();
    }
}
